<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Flex弹性盒 | Brilliance02</title><meta name="keywords" content="css"><meta name="author" content="张朝辉"><meta name="copyright" content="张朝辉"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="学习Flex弹性盒的一些笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="Flex弹性盒">
<meta property="og:url" content="http://brilliance02.gitee.io/2023/04/19/Flex%E5%BC%B9%E6%80%A7%E7%9B%92/index.html">
<meta property="og:site_name" content="Brilliance02">
<meta property="og:description" content="学习Flex弹性盒的一些笔记">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://brilliance02.gitee.io/img/14.jpg">
<meta property="article:published_time" content="2023-04-19T13:08:37.586Z">
<meta property="article:modified_time" content="2022-06-07T02:26:27.806Z">
<meta property="article:author" content="张朝辉">
<meta property="article:tag" content="css">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://brilliance02.gitee.io/img/14.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://brilliance02.gitee.io/2023/04/19/Flex%E5%BC%B9%E6%80%A7%E7%9B%92/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Flex弹性盒',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-06-07 10:26:27'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.2.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/1.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">4</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">3</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/14.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Brilliance02</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Flex弹性盒</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T13:08:37.586Z" title="发表于 2023-04-19 21:08:37">2023-04-19</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-06-07T02:26:27.806Z" title="更新于 2022-06-07 10:26:27">2022-06-07</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/css/">css</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>4分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Flex弹性盒"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="flex布局"><a href="#flex布局" class="headerlink" title="flex布局"></a>flex布局</h1><table>
<thead>
<tr>
<th>传统布局</th>
<th>flex弹性布局</th>
</tr>
</thead>
<tbody><tr>
<td>兼容性好</td>
<td>操作方便，布局极为简单，移动端应用很广泛</td>
</tr>
<tr>
<td>布局繁琐</td>
<td>PC 端浏览器支持情况较差</td>
</tr>
<tr>
<td>局限性，不能再移动端很好的布局</td>
<td>IE 11或更低版本，不支持或仅部分支持传统布局</td>
</tr>
</tbody></table>
<p>建议：</p>
<ol>
<li>如果是PC端页面布局，我们还是传统布局。</li>
<li>如果是移动端或者不考虑兼容性问题的PC端页面布局，我们还是使用flex弹性布局</li>
</ol>
<h2 id="flex布局原理"><a href="#flex布局原理" class="headerlink" title="flex布局原理"></a>flex布局原理</h2><p>flex 是 flexible Box 的缩写，意为”弹性布局”，用来为盒状模型提供最大的灵活性，任何一个容器都可以指定为 flex 布局。</p>
<ul>
<li>当我们为父盒子设为 flex 布局以后，子元素的 float、clear 和 vertical-align 属性将失效。</li>
<li>伸缩布局 &#x3D; 弹性布局 &#x3D; 伸缩盒布局 &#x3D; 弹性盒布局 &#x3D;flex布局</li>
</ul>
<p>采用 Flex 布局的元素，称为 <strong>Flex 容器</strong>（flex container），简称”容器”。它的所有子元素自动成为容器成员，称为 <strong>Flex 项目</strong>（flex item），简称”项目”。</p>
<p><img src="https://img-blog.csdnimg.cn/d27de399dbd64e5db668e9d20c8b48bd.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA55Sf5ZG95piv5pyJ5YWJ55qE,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p>
<blockquote>
<p>总结 flex 布局原理：<strong>就是通过给父盒子添加 flex 属性，来控制子盒子的位置和排列方式。</strong></p>
</blockquote>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//给父级设置！！！！</span><br><span class="line"><span class="attribute">display</span>:flex;</span><br></pre></td></tr></table></figure>

<h2 id="flex布局常见父项属性"><a href="#flex布局常见父项属性" class="headerlink" title="flex布局常见父项属性"></a>flex布局常见父项属性</h2><ul>
<li>flex-direction：设置主轴的方向</li>
<li>justify-content：设置主轴上的子元素排列方式</li>
<li>flex-wrap：设置子元素是否换行</li>
<li>align-content：设置侧轴上的子元素的排列方式（多行）</li>
<li>align-items：设置侧轴上的子元素排列方式（单行）</li>
<li>flex-flow：复合属性，相当于同时设置了 flex-direction 和 flex-wrap</li>
</ul>
<h4 id="flex-direction设置主轴方向"><a href="#flex-direction设置主轴方向" class="headerlink" title="flex-direction设置主轴方向"></a>flex-direction设置主轴方向</h4><p>主轴和侧轴：在 flex 布局中，是分为主轴和侧轴两个方向，同样的叫法有：行和列、x轴和y轴</p>
<ul>
<li>默认主轴方向就是 x 轴方向，水平向右</li>
<li>默认侧轴方向就是 y 轴方向，水平向下</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/513ae11d9f4041949b450c2c1a40dc7e.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA55Sf5ZG95piv5pyJ5YWJ55qE,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p>
<ul>
<li>flex-direction 属性决定主轴的方向（即项目的排列方向）</li>
<li>注意： 主轴和侧轴是会变化的，就看 flex-direction 设置谁为主轴，剩下的就是侧轴。而我们的子元素是跟着主轴来排列的</li>
</ul>
<table>
<thead>
<tr>
<th>属性值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><strong>row</strong></td>
<td><strong>默认值从左到右</strong></td>
</tr>
<tr>
<td>row-reverse</td>
<td>从右到左</td>
</tr>
<tr>
<td><strong>column</strong></td>
<td><strong>从上到下</strong></td>
</tr>
<tr>
<td>column-reverse</td>
<td>从下到上</td>
</tr>
</tbody></table>
<h4 id="justify-content-设置主轴上的子元素排列方式"><a href="#justify-content-设置主轴上的子元素排列方式" class="headerlink" title="justify-content 设置主轴上的子元素排列方式"></a>justify-content 设置主轴上的子元素排列方式</h4><ul>
<li><p>justify-content 属性定义了项目在主轴上的对齐方式</p>
</li>
<li><p><strong>注意： 使用这个属性之前一定要确定好主轴是哪个</strong></p>
</li>
<li><table>
<thead>
<tr>
<th>属性值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><strong>flex-start</strong></td>
<td><strong>默认值从头部开始，如果主轴是x轴，则从左到右</strong></td>
</tr>
<tr>
<td>flex-end</td>
<td>从尾部开始排列</td>
</tr>
<tr>
<td><strong>center</strong></td>
<td><strong>在主轴居中对齐(如果主轴是 x 轴则水平居中)</strong></td>
</tr>
<tr>
<td><strong>space-around</strong></td>
<td><strong>平分剩余空间</strong></td>
</tr>
<tr>
<td><strong>space-between</strong></td>
<td><strong>先两边贴边，再平分剩余空间🔥</strong></td>
</tr>
</tbody></table>
</li>
</ul>
<h4 id="flex-wrap-设置子元素是否换行"><a href="#flex-wrap-设置子元素是否换行" class="headerlink" title="flex-wrap 设置子元素是否换行"></a>flex-wrap 设置子元素是否换行</h4><p>默认情况下，项目都排在一条线（又称”轴线”）上。flex-wrap属性定义，flex布局中默认是不换行的。</p>
<p>意思就是如果按照我们设置的盒子大小，一行只能装 3 个盒子，但是我们有 5 个盒子，那么 flex 布局默认会给我们塞上去，自动缩小盒子大小。</p>
<table>
<thead>
<tr>
<th>属性值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>nowrap</td>
<td>默认值，不换行</td>
</tr>
<tr>
<td><strong>wrap</strong></td>
<td><strong>换行</strong></td>
</tr>
</tbody></table>
<h4 id="align-items-设置侧轴上的子元素排列方式-单行"><a href="#align-items-设置侧轴上的子元素排列方式-单行" class="headerlink" title="align-items 设置侧轴上的子元素排列方式(单行)"></a>align-items 设置侧轴上的子元素排列方式(单行)</h4><p>该属性是控制子项在侧轴（默认是y轴）上的排列方式 在子项为单项（<strong>单行</strong>）的时候使用</p>
<table>
<thead>
<tr>
<th>属性值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><strong>flex-start</strong></td>
<td><strong>从上到下</strong></td>
</tr>
<tr>
<td>flex-end</td>
<td>从下到上</td>
</tr>
<tr>
<td><strong>center</strong></td>
<td><strong>挤在一起居中(垂直居中)</strong></td>
</tr>
<tr>
<td><strong>stretch</strong></td>
<td><strong>拉伸(默认值)没有给子元素指定宽度时</strong></td>
</tr>
</tbody></table>
<h4 id="align-content-设置侧轴上的子元素的排列方式-多行"><a href="#align-content-设置侧轴上的子元素的排列方式-多行" class="headerlink" title="align-content 设置侧轴上的子元素的排列方式(多行)"></a>align-content 设置侧轴上的子元素的排列方式(多行)</h4><p>设置子项在侧轴上的排列方式 并且只能用于子项出现 <strong>换行</strong> 的情况（多行），在单行下是没有效果的。</p>
<table>
<thead>
<tr>
<th>属性值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><strong>flex-start</strong></td>
<td><strong>默认值在侧轴的头部开始排列</strong></td>
</tr>
<tr>
<td>flex-end</td>
<td>在侧轴的尾部开始排列</td>
</tr>
<tr>
<td><strong>center</strong></td>
<td><strong>在侧轴中间显示</strong></td>
</tr>
<tr>
<td><strong>space-around</strong></td>
<td><strong>子项在侧轴平分剩余空间</strong></td>
</tr>
<tr>
<td><strong>space-between</strong></td>
<td><strong>子项在侧轴先分布在两头，再平分剩余空间</strong></td>
</tr>
<tr>
<td><strong>stretch</strong></td>
<td><strong>设置子项元素高度平分父元素高度</strong></td>
</tr>
</tbody></table>
<h4 id="align-content-和-align-items-区别"><a href="#align-content-和-align-items-区别" class="headerlink" title="align-content 和 align-items 区别"></a>align-content 和 align-items 区别</h4><ul>
<li>align-items 适用于单行情况下， 只有上对齐、下对齐、居中和 拉伸</li>
<li>align-content 适应于换行（多行）的情况下（单行情况下无效）， 可以设置 上对齐、 下对齐、居中、拉伸以及平均分配剩余空间等属性值。</li>
<li>总结就是单行找 align-items 多行找 align-content</li>
</ul>
<h3 id="flex-flow"><a href="#flex-flow" class="headerlink" title="flex-flow"></a>flex-flow</h3><p>flex-flow 属性是 flex-direction 和 flex-wrap 属性的复合属性</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">flex-flow</span>: row wrap;</span><br></pre></td></tr></table></figure>

<h2 id="flex布局子项常见属性"><a href="#flex布局子项常见属性" class="headerlink" title="flex布局子项常见属性"></a>flex布局子项常见属性</h2><ul>
<li>flex 子项目占的份数</li>
<li>align-self 控制子项自己在侧轴的排列方式</li>
<li>order属性定义子项的排列顺序（前后顺序）</li>
</ul>
<h3 id="flex属性"><a href="#flex属性" class="headerlink" title="flex属性"></a>flex属性</h3><p>flex 属性定义子项目<strong>分配剩余空间</strong>，用flex来表示占多少份数。</p>
<h3 id="align-self-控制子项自己在侧轴上的排列方式"><a href="#align-self-控制子项自己在侧轴上的排列方式" class="headerlink" title="align-self 控制子项自己在侧轴上的排列方式"></a>align-self 控制子项自己在侧轴上的排列方式</h3><ul>
<li>align-self 属性允许单个项目有与其他项目不一样的对齐方式，可覆盖 align-items 属性。</li>
<li>默认值为 auto，表示继承父元素的 align-items 属性，如果没有父元素，则等同于 stretch。</li>
</ul>
<h3 id="order属性定义项目的排列顺序"><a href="#order属性定义项目的排列顺序" class="headerlink" title="order属性定义项目的排列顺序"></a>order属性定义项目的排列顺序</h3><p>数值越小，排列越靠前，默认为0。</p>
<p>注意：和 z-index 不一样。</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://brilliance02.gitee.io">张朝辉</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://brilliance02.gitee.io/2023/04/19/Flex%E5%BC%B9%E6%80%A7%E7%9B%92/">http://brilliance02.gitee.io/2023/04/19/Flex%E5%BC%B9%E6%80%A7%E7%9B%92/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://brilliance02.gitee.io" target="_blank">Brilliance02</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/css/">css</a></div><div class="post_share"><div class="social-share" data-image="/img/14.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/gh/overtrue/share.js@master/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/2022/06/07/reg/"><img class="next-cover" src="/img/7.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">正则表达式</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/1.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">张朝辉</div><div class="author-info__description">欢迎进入ZZH's Blog</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">4</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">3</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#flex%E5%B8%83%E5%B1%80"><span class="toc-number">1.</span> <span class="toc-text">flex布局</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#flex%E5%B8%83%E5%B1%80%E5%8E%9F%E7%90%86"><span class="toc-number">1.1.</span> <span class="toc-text">flex布局原理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#flex%E5%B8%83%E5%B1%80%E5%B8%B8%E8%A7%81%E7%88%B6%E9%A1%B9%E5%B1%9E%E6%80%A7"><span class="toc-number">1.2.</span> <span class="toc-text">flex布局常见父项属性</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#flex-direction%E8%AE%BE%E7%BD%AE%E4%B8%BB%E8%BD%B4%E6%96%B9%E5%90%91"><span class="toc-number">1.2.0.1.</span> <span class="toc-text">flex-direction设置主轴方向</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#justify-content-%E8%AE%BE%E7%BD%AE%E4%B8%BB%E8%BD%B4%E4%B8%8A%E7%9A%84%E5%AD%90%E5%85%83%E7%B4%A0%E6%8E%92%E5%88%97%E6%96%B9%E5%BC%8F"><span class="toc-number">1.2.0.2.</span> <span class="toc-text">justify-content 设置主轴上的子元素排列方式</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#flex-wrap-%E8%AE%BE%E7%BD%AE%E5%AD%90%E5%85%83%E7%B4%A0%E6%98%AF%E5%90%A6%E6%8D%A2%E8%A1%8C"><span class="toc-number">1.2.0.3.</span> <span class="toc-text">flex-wrap 设置子元素是否换行</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#align-items-%E8%AE%BE%E7%BD%AE%E4%BE%A7%E8%BD%B4%E4%B8%8A%E7%9A%84%E5%AD%90%E5%85%83%E7%B4%A0%E6%8E%92%E5%88%97%E6%96%B9%E5%BC%8F-%E5%8D%95%E8%A1%8C"><span class="toc-number">1.2.0.4.</span> <span class="toc-text">align-items 设置侧轴上的子元素排列方式(单行)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#align-content-%E8%AE%BE%E7%BD%AE%E4%BE%A7%E8%BD%B4%E4%B8%8A%E7%9A%84%E5%AD%90%E5%85%83%E7%B4%A0%E7%9A%84%E6%8E%92%E5%88%97%E6%96%B9%E5%BC%8F-%E5%A4%9A%E8%A1%8C"><span class="toc-number">1.2.0.5.</span> <span class="toc-text">align-content 设置侧轴上的子元素的排列方式(多行)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#align-content-%E5%92%8C-align-items-%E5%8C%BA%E5%88%AB"><span class="toc-number">1.2.0.6.</span> <span class="toc-text">align-content 和 align-items 区别</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#flex-flow"><span class="toc-number">1.2.1.</span> <span class="toc-text">flex-flow</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#flex%E5%B8%83%E5%B1%80%E5%AD%90%E9%A1%B9%E5%B8%B8%E8%A7%81%E5%B1%9E%E6%80%A7"><span class="toc-number">1.3.</span> <span class="toc-text">flex布局子项常见属性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#flex%E5%B1%9E%E6%80%A7"><span class="toc-number">1.3.1.</span> <span class="toc-text">flex属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#align-self-%E6%8E%A7%E5%88%B6%E5%AD%90%E9%A1%B9%E8%87%AA%E5%B7%B1%E5%9C%A8%E4%BE%A7%E8%BD%B4%E4%B8%8A%E7%9A%84%E6%8E%92%E5%88%97%E6%96%B9%E5%BC%8F"><span class="toc-number">1.3.2.</span> <span class="toc-text">align-self 控制子项自己在侧轴上的排列方式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#order%E5%B1%9E%E6%80%A7%E5%AE%9A%E4%B9%89%E9%A1%B9%E7%9B%AE%E7%9A%84%E6%8E%92%E5%88%97%E9%A1%BA%E5%BA%8F"><span class="toc-number">1.3.3.</span> <span class="toc-text">order属性定义项目的排列顺序</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/04/19/Flex%E5%BC%B9%E6%80%A7%E7%9B%92/" title="Flex弹性盒"><img src="/img/14.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Flex弹性盒"/></a><div class="content"><a class="title" href="/2023/04/19/Flex%E5%BC%B9%E6%80%A7%E7%9B%92/" title="Flex弹性盒">Flex弹性盒</a><time datetime="2023-04-19T13:08:37.586Z" title="发表于 2023-04-19 21:08:37">2023-04-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/06/07/reg/" title="正则表达式"><img src="/img/7.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="正则表达式"/></a><div class="content"><a class="title" href="/2022/06/07/reg/" title="正则表达式">正则表达式</a><time datetime="2022-06-07T02:34:40.000Z" title="发表于 2022-06-07 10:34:40">2022-06-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/06/07/this/" title="JS的作用域和this"><img src="/img/11.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS的作用域和this"/></a><div class="content"><a class="title" href="/2022/06/07/this/" title="JS的作用域和this">JS的作用域和this</a><time datetime="2022-06-07T02:29:50.000Z" title="发表于 2022-06-07 10:29:50">2022-06-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/06/07/article/" title="回调函数和异步机制"><img src="/img/6.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="回调函数和异步机制"/></a><div class="content"><a class="title" href="/2022/06/07/article/" title="回调函数和异步机制">回调函数和异步机制</a><time datetime="2022-06-07T01:39:35.000Z" title="发表于 2022-06-07 09:39:35">2022-06-07</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2023 By 张朝辉</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my blog !</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>